<template>
	<view>
		<view class="cu-modal" :class="show?'show':''">
			<view class="cu-dialog">
				<view class="cu-bar bg-white justify-end">
					<view class="text-bold content">提示</view>
					<!-- <view class="action" @tap="hideModal">
						<text class="cuIcon-close text-red"></text>
					</view> -->
				</view>
				<view class="text-lg padding-xl">
					您尚未登录，请在登录后继续
				</view>
				<view class="cu-bar bg-white justify-center">
					<view class="action">
						<button open-type="getUserInfo" class="cu-btn bg-green" @getuserinfo="handleLogin">确定</button>
						<button class="cu-btn line-green margin-left-lg text-green" @tap="handleCancel">取消</button>
		
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex';
	import {wxLogin} from '../../request/handleReq.js';
	import {request} from '../../request/request.js';
	export default {
		// computed:mapState(['forcedLogin']),
		data() {
			return {
				show:false,
				lastPage:'',
				hasUserInfo:null,
				userInfo:null
			}
		},
		
		onLoad(options) {
			
			this.showModal();
			// console.log(options);
			
		},
		
		
		methods: {
			...mapMutations(['login']),
			showModal(){
				this.show = true;
			},
			hideModal(){
				this.show = false;
			},
			
			handleLogin({detail}){
				// wxLogin();
				uni.showLoading({
				    title:'请稍候...',
				    mask:true
				});
				this.userAuthorized();
				
				// this.forceLogin(false);
				// if(detail.userInfo){
				// 	this.login(detail.userInfo);
					
					
				// 	uni.reLaunch({
				// 		url:'../index/index'
				// 	})
					
					
					
					
				// }else{
				// 	uni.showToast({
				// 		icon:'none',
				// 		title:'登录失败',
				// 		mask:true
				// 	})
				// }
				
			},
			
			handleCancel(){
				uni.navigateBack({
					delta:1
				});
			},
			
			userAuthorized(){
				let that = this;
				uni.getSetting({
					success:data => {
						if(data.authSetting['scope.userInfo']){
							uni.getUserInfo({
								success:data => {
									// that.hasUserInfo = true,
									// that.userInfo = data.userInfo,
									that.onGetUserInfo(data)
								}
							})
						}else{
							// that.hasUserInfo = false
							uni.reLaunch({
								url: '../index/index'
							})
						}
					},
					fail:function(error){
						console.log(error);
						
					}
				})
			},
			onGetUserInfo(userData){
				wxLogin(userData);
							
			}
			
		}
	}
</script>

<style>

</style>
